package gowcage.tfgame;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import java.util.Vector;

public class Map {
    short map0[][] = {
            {0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
            {1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
            {1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
            {1, 0, 1, 0, 1, 0, 0, 1, 0, 1},
            {1, 0, 1, 0, 1, 1, 0, 1, 0, 1},
            {1, 0, 1, 0, 1, 1, 0, 1, 0, 1},
            {1, 0, 1, 0, 0, 0, 0, 1, 0, 1},
            {1, 0, 1, 1, 1, 1, 1, 1, 0, 1},
            {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
            {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
    };


    public Vector getWay(int a, int b) {//计算小人移动的路径
        Vector v = new Vector();//路径以地图位标（ij）形式存在这里
        int temp = 0;
        int j = a;
        int i = b;
        while (true) {
            if (temp != 2 && i + 1 < map0.length && map0[i + 1][j] == 0) {
                i++;
                temp = 1;
                v.addElement(new int[]{i, j});
                continue;
            }
            if (temp != 1 && i - 1 >= 0 && map0[i - 1][j] == 0) {
                i--;
                temp = 2;
                v.addElement(new int[]{i, j});
                continue;
            }
            if (temp != 4 && j + 1 < map0.length && map0[i][j + 1] == 0) {
                j++;
                temp = 3;
                v.addElement(new int[]{i, j});
                continue;
            }
            if (temp != 3 && j - 1 >= 0 && map0[i][j - 1] == 0) {
                j--;
                temp = 4;
                v.addElement(new int[]{i, j});
                continue;
            }
            break;
        }
        return v;
    }

    public void paint(Canvas c, Paint p) {//画地图
        p.setColor(Color.YELLOW);
        for (int i = 0; i < map0.length; i++) {
            for (int j = 0; j < map0[i].length; j++) {
                if (map0[i][j] != 0)
                    c.drawRect(j * 32, i * 32, j * 32 + 32, i * 32 + 32, p);
            }
        }
    }
}
